package contracts.program

import org.springframework.cloud.contract.spec.Contract

Contract.make {
    request {
        method 'GET'
        url value(consumer(regex('/api/diff/programs/[0-9]+')),
                producer('/api/diff/programs/1'))
    }
    response {
        status 200
        headers {
            header('Content-Type', 'application/json;charset=UTF-8')
        }
        body("""
                 [{
                    "programId":1,
                    "startTime":"2019-09-12",
                    "endTime":"2019-10-12",
                    "category":"paid",
                    "introduction":"introduction",
                    "fromId":1,
                    "studentLink":true,
                    "tutorLink":true,
                    "isReadOnly":true,
                    "isExpired":true,
                    "available":true,
                    "organizationId":1,
                    "operatorId":1,
                    "title":"title",
                    "operation":"UPDATE",
                    "topics":[
                        {
                        "id":1,
                        "topicId":1,
                        "programId":1,
                        "fromId":0,
                        "title": "topic",
                        "operation": "CREATE",
                        "operatorId": 1,
                        "tasks":[
                            {"id": 1,
                            "topicId": 1,
                            "taskId": 1,
                            "title": "task",
                            "content": "content",
                            "visible": true,
                            "operation": "CREATE"}
                        ]
                        }
                    ]
                 }] 
                """
        )
        bodyMatchers {
            jsonPath('$.[*]', byType())
            jsonPath('$.[*].programId', byRegex(number()))
            jsonPath('$.[*].startTime', byRegex("[\\s\\S]+"))
            jsonPath('$.[*].endTime', byRegex("[\\s\\S]+"))
            jsonPath('$.[*].category', byRegex("[\\s\\S]+"))
            jsonPath('$.[*].introduction', byRegex("[\\s\\S]+"))
            jsonPath('$.[*].fromId', byRegex(number()))
            jsonPath('$.[*].studentLink', byRegex(nonEmpty()))
            jsonPath('$.[*].tutorLink', byRegex(nonEmpty()))
            jsonPath('$.[*].isReadOnly', byRegex(nonEmpty()))
            jsonPath('$.[*].isExpired', byRegex(nonEmpty()))
            jsonPath('$.[*].available', byRegex(nonEmpty()))
            jsonPath('$.[*].organizationId', byRegex(number()))
            jsonPath('$.[*].title', byRegex("[\\s\\S]+"))
            jsonPath('$.[*].operation', byRegex("[\\s\\S]+"))
            jsonPath('$.[*].topics', byRegex(nonEmpty()))
        }
    }
}
